package me.leiusual.sharing.ui.useraccount.adapter

import android.view.View
import androidx.recyclerview.widget.RecyclerView
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.view_holder_user_account_detail.*
import me.leiusual.sharing.api.model.UserAccountLog
import me.leiusual.sharing.util.extension.toSpanned

/**
 * author: leiusual
 * create on: 2019-08-06
 * description:
 */
class UserAccountDetailViewHolder(
    private val type: String,
    override val containerView: View
) : RecyclerView.ViewHolder(containerView), LayoutContainer {

  fun bind(userAccountLog: UserAccountLog) {

    when (type) {
      "user" -> {
        val builder = StringBuilder()
        builder.append("""操作类型：${userAccountLog.operationTypeName}""")
        builder.append("""<br/>账户名称：${userAccountLog.accountTypeName}""")
        builder.append("""<br/>变动额度：${userAccountLog.amount}""")
        builder.append("""<br/>变后余额：${userAccountLog.balanceAfterChanged}""")
        builder.append("""<br/>变动描述：${userAccountLog.description}""")
        builder.append("""<br/>创建时间：${userAccountLog.createTime}""")
        text_view.text = builder.toString().toSpanned()
      }
      "store" -> {
        val builder = StringBuilder()
        builder.append("""操作类型：${userAccountLog.operationTypeName}""")
        builder.append("""<br/>账户名称：${userAccountLog.accountTypeName}""")
        if (userAccountLog.amount.toDoubleOrNull() ?: 0.0 != 0.0) {
          builder.append("""<br/>变动额度：${userAccountLog.amount}""")
        }
        if (userAccountLog.balanceAfterChanged.toDoubleOrNull() ?: 0.0 != 0.0) {
          builder.append("""<br/>变后余额：${userAccountLog.balanceAfterChanged}""")
        }
        if (userAccountLog.notArrivedAmount.toDoubleOrNull() ?: 0.0 != 0.0) {
          builder.append("""<br/>未到账资金变动额度：${userAccountLog.notArrivedAmount}""")
        }
        if (userAccountLog.notArrivedBalanceAfterChanged.toDoubleOrNull() ?: 0.0 != 0.0) {
          builder.append("""<br/>未到账资金变后总额：${userAccountLog.notArrivedBalanceAfterChanged}""")
        }
        builder.append("""<br/>变动原因：${userAccountLog.changeOrigin}""")
        builder.append("""<br/>变动时间：${userAccountLog.changeTime}""")
        builder.append("""<br/>变动描述：${userAccountLog.description}""")
        builder.append("""<br/>创建时间：${userAccountLog.createTime}""")
        text_view.text = builder.toString().toSpanned()
      }
    }
  }
}